﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Collections;
using System.Data.Metadata.Edm;
using System.Linq.Expressions;
using ZhQuiz;

namespace ZhQuiz.Models
{
    public class SystemModels
    {

    }
    public interface iBizObjList
    {
        string ObjName { get; set; }
        IEnumerable<EntityObject> Data { get; }
        System.Data.Metadata.Edm.EntitySet EntitySet { get; }
        Func<iBizObjList, object> ValueOf(EntityObject obj, string prop);
    }

    public interface iBizObjItem
    {
        string ObjName { get; set; }
        EntityObject Data { get; }
    }
    public class BizObjList<T> : iBizObjList where T : EntityObject
    {
        public string ObjName { get; set; }
        public ObjectSet<T> ObjectSet { get; set; }
        public EntitySet EntitySet
        {
            get { return ObjectSet.EntitySet; }
        }
        public IEnumerable<EntityObject> Data
        {
            get
            {
                return ObjectSet.ToList();
            }
        }


        public Func<iBizObjList, object> ValueOf(EntityObject obj, string prop)
        {
            //return Expression.Lambda<iBizObjList, object>(Expression.Property(typeof(T), prop), obj);
            //var v = Expression.Parameter(typeof(T), "v");
            var lambda = Expression.Lambda<Func<iBizObjList, object>>(
                Expression.Property(Expression.Constant(obj), prop)
                ).Compile();
            return lambda;
        }
    }
    public class BizObjItem : iBizObjItem
    {
        public string ObjName { get; set; }
        public EntityObject Data { get; set; }
    }

    public class BizObjItem<T> where T : EntityObject
    {
        public string ObjName { get; set; }
        public T Data { get; set; }
    }


    public class NewLink
    {
        public string DialogTitle { get; set; }
        public string UpdateTargetId { get; set; }
        public string Title { get; set; }
        public string Action { get; set; }
        public System.Web.Routing.RouteValueDictionary RouterValues { get; set; }

        public NewLink()
        {

        }
        public NewLink(string updatetargetid, string action)
            : this(updatetargetid, action, "新建", "新建")
        {

        }
        public NewLink(string updatetargetid, string action, string title)
            : this(updatetargetid, action, title, "新建")
        {
        }

        public NewLink(string updatetargetid, string action, string title, string dialogtitle)
        {
            UpdateTargetId = updatetargetid; Action = action; Title = title; DialogTitle = DialogTitle;
        }


    }

    public class CommonSearchValues
    {
        public string V0 { get; set; }
        public string V1 { get; set; }
        public string V2 { get; set; }
        public string V3 { get; set; }
        public string V4 { get; set; }
        public string V5 { get; set; }
        public string V6 { get; set; }
    }

    public class CommonSearchValues2 : CommonSearchValues
    {
        public string V7 { get; set; }
        public string V8 { get; set; }
        public string V9 { get; set; }
        public string V10 { get; set; }
        public string V11 { get; set; }
        public string V12 { get; set; }
    }

    public class CommonSearchValues2<T1, T2, T3> : CommonSearchValues
    {
        public T1 V11 { get; set; }
        public T2 V12 { get; set; }
        public T3 V13 { get; set; }
    }

    public class ListViewModel<T, M>
    {
        public T SearchFrom { get; set; }
        public T SearchTo { get; set; }
        public M Data { get; set; }
        public int PageCount { get; set; }
        public int PageIdx { get; set; }
        private int _PageSize = Controllers.Services.DefaultPageSize;
        public int PageSize { get { return _PageSize; } set { _PageSize = value; } }
        protected int _ItemCount;
        public int ItemCount
        {
            get { return _ItemCount; }
            set
            {
                _ItemCount = value;
                PageCount = (int)Math.Ceiling((double)_ItemCount / PageSize);
            }
        }
        public T Tag { get; set; }
    }


    public class PaggerViewModel
    {
        public int PageIdx { get; set; }
        public int PageCount { get; set; }
        public string Act { get; set; }
        public string SubmitButtonId { get; set; }
        public string PageIdxValueControlID { get; set; }
        public int ItemCount { get; set; }
    }
}